//
//  TouristsViewController.m
//  mentor
//
//  Created by 孙宏峰的MacPro on 2018/7/4.
//  Copyright © 2018年 孙宏峰的MacPro. All rights reserved.
//

#import "TouristsViewController.h"

#import "LoginVC.h"





@interface TouristsViewController ()<UIWebViewDelegate>
@property (strong, nonatomic) UIWebView *webView;

@end

@implementation TouristsViewController


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.userNameLabel.text = @"用户名";
    self.userHeadImage.image = [UIImage imageNamed:@"user_de"];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = nil;
    
    self.view.backgroundColor = [UIColor redColor];

    NSString * urlStr = [NSString stringWithFormat:@"%@%@.html",HTML_HOST_HEADER,HTML_ACTION_MAININDEX];
    urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];//ios 9以后
    NSURL *url = [NSURL URLWithString:urlStr];

    //TODO::测试
    NSURLRequest * request = [NSURLRequest requestWithURL:url cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30];
    
    NSLog(@"request:%@",request);
    [self.webView loadRequest:request];
    
    [self checkVersion];
    [self.view addSubview:self.webView];
//
}


#pragma mark - life cycle
#pragma mark - UITableViewDelegate
#pragma mark - customDelegate
#pragma mark - event Response
#pragma mark - private methods
/*!@brief ****   检查版本更新接口 */
- (void)checkVersion
{

    [HFNetWork getURL:Version withParameters:@{@"platform":@"ios"} withOperationCancel:NO Success:^(NSDictionary *result) {
        if([result[@"data"] isKindOfClass:[NSNull class]] || [result[@"code"] integerValue] != 0) return ;
        NSString *versionStr = result[@"version"];
        NSString * appversion = APP_VERSION;
        NSString * iosIpaUrl = [NSString noNull:result[@"iosIpaUrl"]];
        
        if ([versionStr compare:appversion] != NSOrderedDescending) {

        }else
        {
            DDAlertView * alertView = [[DDAlertView alloc] initCloseWithTitle:@"提示" close:@"" message:result[@"content"] leftName:@"取消" rightName:@"确定" clickLeft:^{
                
            } clickRight:^{
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iosIpaUrl]];
            }];
            [alertView show];
        }

    } failure:^(NSDictionary *error) {
        
    }];
}
- (void)userCenter
{
    NSLog(@"点击头像");
    LoginVC * logVC = [LoginVC new];
    [self.navigationController pushViewController:logVC animated:YES];
    
}
#pragma mark - getters and setters
#pragma mark - getters and setters
- (UIWebView *)webView
{
    if (!_webView ) {
        _webView = [[UIWebView alloc] initWithFrame:(CGRectMake(0, 0, KScreenWidth, KScreenHeight - 64))];
        _webView.delegate = self;
        _webView.scrollView.bounces = NO;
    }
    return _webView;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"打印：%@",request.URL.absoluteString);
    NSString *absoluteString = request.URL.absoluteString;
    return YES;
}

@end
